package org.xu.logic;

import com.core.utils.HttpFormUtil;
import com.core.utils.UUIDGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xu.entity.WorkFlowLogEntity;
import org.xu.enums.WorkTypeEnum;
import org.xu.service.WorkFlowLogService;

import java.util.Date;

@Slf4j
@Service
public class WeChatTaskLogicImpl implements WeChatTaskLogic{

    @Autowired
    private WorkFlowLogService workFlowLogService;
    private static final String dataIdStr = "signIn_view_finish";
    // 看视频
    public void videoFinish(String key,String token) {
        StringBuffer sbf = new StringBuffer();
        sbf.append("------WebKitFormBoundaryFkeeAp6wNFOJe0rx\r\n")
                .append("Content-Disposition: form-data; name=\"token\"\r\n")
                .append("\r\n")
                .append(token.trim())
                .append("\r\n------WebKitFormBoundaryFkeeAp6wNFOJe0rx\r\n")
                .append("Content-Disposition: form-data; name=\"task_id\"\r\n")
                .append("\r\n")
                .append(2)
                .append("\r\n------WebKitFormBoundaryFkeeAp6wNFOJe0rx\r\n")
                .append("Content-Disposition: form-data; name=\"score\"\r\n")
                .append("\r\n")
                .append(1)
                .append("\r\n------WebKitFormBoundaryFkeeAp6wNFOJe0rx--");
        String urlString = "https://h5up.bluebirdh5.top/sq/YxDecennial/submitTask";
        String response = HttpFormUtil.formCommit("看视频提交",urlString, sbf.toString(), "----WebKitFormBoundaryFkeeAp6wNFOJe0rx");
        if (!"失败".equals(response)){
            // 构建表单数据
            WorkFlowLogEntity entity = new WorkFlowLogEntity();
            entity.setId(UUIDGenerator.generate());
            entity.setDataId(dataIdStr);
            entity.setApplyNo("test_"+key);
            entity.setCreateTime(new Date());
            entity.setOperationResult(key + ":看视频完成");
            entity.setRemark(response);
            entity.setDeleted(false);
            entity.setWorkType(WorkTypeEnum.SIGN);
            workFlowLogService.insert(entity);
        }
    }



}
